//
//  XSNavigationController.m
//  AudioVideo
//
//  Created by xueshan1 on 2019/8/29.
//  Copyright © 2019 xueshan1. All rights reserved.
//

#import "XSNavigationController.h"

@interface XSNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation XSNavigationController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    //返回手势(全屏)
    //    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
    //    [self.view addGestureRecognizer:pan];
    //    pan.delegate = self;
    //    self.interactivePopGestureRecognizer.enabled = NO;
    
    self.interactivePopGestureRecognizer.delegate = self;
    
    [self.navigationBar setBackgroundImage:[UIImage imageWithColor: Theme_Color] forBarMetrics:UIBarMetricsDefault];
    self.navigationBar.translucent = YES;//如若不透明,则vc的self.view y坐标自动下移 64
    [self.navigationBar setTintColor: [UIColor whiteColor]];
    [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self.navigationBar setBackIndicatorImage: ImageName(@"zl_navBack")];
    [self.navigationBar setBackIndicatorTransitionMaskImage:ImageName(@"zl_navBack")];

    
}


//消除方法警告
-(void)handleNavigationTransition:(UIPanGestureRecognizer *)pan{
    
}

// 决定是否触发手势
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    return self.childViewControllers.count > 1;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.childViewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem backItemWithimage:[UIImage imageNamed:@"zl_navBack"] highImage:[UIImage imageNamed:@"zl_navBack"]  target:self action:@selector(back) title:@"返回"];
 
    }
    [super pushViewController:viewController animated:animated];
}

- (void)back{
    [KeyWindow endEditing:YES];
    
    [self popViewControllerAnimated:YES];
}
//让状态栏由控制器自己决定
- (UIViewController *)childViewControllerForStatusBarStyle{
    return self.topViewController;
}

@end
